﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Terran
{
	public class ActionCallMule : Action
	{
		public static ActionCallMule Instance = new ActionCallMule();

		private ActionCallMule() { }

		public override bool HaveResources(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			for (int c = 0; c < state.OrbitalCommand_Energy.Count; c++)
				if (state.OrbitalCommand_Energy[c] >= 50)
					return true;
			return false;
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.OrbitalCommand.Count > 0;
		}

		public override bool IsInvalid(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.OrbitalCommand.Total == 0;
		}

		public override void Execute(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			for (int c = 0; c < state.OrbitalCommand_Energy.Count; c++)
				if (state.OrbitalCommand_Energy[c] >= 50)
				{
					state.OrbitalCommand_Energy[c] -= 50;
					break;
				}
			state.Mules++;

			bo.AddAction(state.Time + 90, new ActionGeneric("ActionFailedMule", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				TerranState ibostate = ibo.State as TerranState;
				ibostate.Mules--;
			}));
		}

		private IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceOrbitalCommand.Instance } };
				return m_Requirements;
			}
		}

	}
}
